package com.yidian.controller.security;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author whb
 * @create 2021-06-09 10:22
 * @desciption 获取登录用户信息的控制类
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @GetMapping("/getLoginName")
    public Map<String,Object> getLoginName(){
        HashMap<String, Object> loginMap = new HashMap<>();
        String loginName = SecurityContextHolder.getContext().getAuthentication().getName();
        loginMap.put("loginName",loginName);
        return loginMap;
    }
}
